#ifndef _PARTITION_H
#define _PARTITION_H
#include <cnix/types.h>

enum {
/* These three have identical behaviour; use the second one if DOS FDISK gets
   confused about extended/logical partitions starting past cylinder 1023. */
  DOS_EXTENDED_PARTITION = 5,
  LINUX_EXTENDED_PARTITION = 0x85,
  WIN98_EXTENDED_PARTITION = 0x0f,
};

struct partition {
	unsigned char boot_ind;		/* 0x80 - active (unused) */
	unsigned char head;		/* ? */
	unsigned char sector;		/* ? */
	unsigned char cyl;		/* ? */
	unsigned char sys_ind;		/* ? */
	unsigned char end_head;		/* ? */
	unsigned char end_sector;	/* ? */
	unsigned char end_cyl;		/* ? */
	unsigned int start_sec;		/* starting sector counting from 0 */
	unsigned int num_sec;		/* nr of sectors in partition */
};

struct fat_boot_sector {
  u8_t  ignored[3]; /* Boot strap short or near jump */
  u8_t  system_id[8]; /* Name - can be used to special case
         partition manager volumes */
  u8_t  sector_size[2]; /* bytes per logical sector */
  u8_t  sec_per_clus; /* sectors/cluster */
  u16_t  reserved; /* reserved sectors */
  u8_t  fats;   /* number of FATs */
  u8_t  dir_entries[2]; /* root directory entries */
  u8_t  sectors[2]; /* number of sectors */
  u8_t  media;    /* media code */
  u16_t  fat_length; /* sectors/FAT */
  u16_t  secs_track; /* sectors per track */
  u16_t  heads;    /* number of heads */
  u32_t  hidden;   /* hidden sectors (unused) */
  u32_t  total_sect; /* number of sectors (if sectors == 0) */
  
  /* The following fields are only used by FAT32 */
  u32_t  fat32_length; /* sectors/FAT */
  u16_t  flags;    /* bit 8: fat mirroring, low 4: active fat */
  u8_t  version[2]; /* major, minor filesystem version */
  u32_t  root_cluster; /* first cluster in root directory */
  u16_t  info_sector;  /* filesystem info sector */
  u16_t  backup_boot;  /* backup boot sector */
  u16_t  reserved2[6]; /* Unused */
};

#define DISK_MAX_PARTS 32
struct partition_table {
	char name[4];
	struct {
		sector_t from;
		sector_t size;		
	} parts[DISK_MAX_PARTS];
	int nr_parts;
};

extern struct partition_table sd_partition_table;
extern void parse_partition(struct partition_table *pt);
#endif
